package com.cskaoyan.service.impl;

import com.cskaoyan.bean.bo.ConfigExpressBO;
import com.cskaoyan.bean.bo.ConfigMallBO;
import com.cskaoyan.bean.bo.ConfigOrderBO;
import com.cskaoyan.bean.bo.ConfigWxBO;
import com.cskaoyan.mapper.MarketSystemMapper;
import com.cskaoyan.service.ConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Tang_XueCheng
 * @description 配置管理模块service实现类
 * @since 2022/04/06 17:15
 */
@Service
public class ConfigurationServiceImpl implements ConfigurationService {

    @Autowired
    MarketSystemMapper marketSystemMapper;


    @Override
    public ConfigMallBO queryConfigMall() {
        String longitudeValue = marketSystemMapper.selectByKeyname("market_mall_longitude");
        String latitudeValue = marketSystemMapper.selectByKeyname("market_mall_latitude");
        String addressValue = marketSystemMapper.selectByKeyname("market_mall_address");
        String qqValue = marketSystemMapper.selectByKeyname("market_mall_qq");
        String phoneValue = marketSystemMapper.selectByKeyname("market_mall_phone");
        String nameValue = marketSystemMapper.selectByKeyname("market_mall_name");
        ConfigMallBO configMallBO = new ConfigMallBO(longitudeValue, latitudeValue, addressValue, qqValue, phoneValue, nameValue);

        return configMallBO;
    }

    @Override
    public void updateConfigMallBO(ConfigMallBO configMallBO) {
        marketSystemMapper.updateByKeyname("market_mall_longitude",configMallBO.getMarket_mall_longitude());
        marketSystemMapper.updateByKeyname("market_mall_latitude",configMallBO.getMarket_mall_latitude());
        marketSystemMapper.updateByKeyname("market_mall_address",configMallBO.getMarket_mall_address());
        marketSystemMapper.updateByKeyname("market_mall_qq",configMallBO.getMarket_mall_qq());
        marketSystemMapper.updateByKeyname("market_mall_phone",configMallBO.getMarket_mall_phone());
        marketSystemMapper.updateByKeyname("market_mall_name",configMallBO.getMarket_mall_name());
    }

    @Override
    public ConfigExpressBO queryExpress() {
        String freightMinValue = marketSystemMapper.selectByKeyname("market_express_freight_min");
        String freightValue = marketSystemMapper.selectByKeyname("market_express_freight_value");
        ConfigExpressBO configExpressBO = new ConfigExpressBO(freightMinValue, freightValue);
        return configExpressBO;
    }

    @Override
    public void updateConfigExpressBO(ConfigExpressBO configExpressBO) {
        marketSystemMapper.updateByKeyname("market_express_freight_min",configExpressBO.getMarket_express_freight_min());
        marketSystemMapper.updateByKeyname("market_express_freight_value",configExpressBO.getMarket_express_freight_value());

    }

    @Override
    public ConfigOrderBO queryOrder() {
        String unconfirm = marketSystemMapper.selectByKeyname("market_order_unconfirm");
        String unpaid = marketSystemMapper.selectByKeyname("market_order_unpaid");
        String comment = marketSystemMapper.selectByKeyname("market_order_comment");
        ConfigOrderBO configOrderBO = new ConfigOrderBO(unconfirm, unpaid, comment);
        return configOrderBO;
    }

    @Override
    public void updateConfigOrderBO(ConfigOrderBO configOrderBO) {
        marketSystemMapper.updateByKeyname("market_order_unconfirm",configOrderBO.getMarket_order_unconfirm());
        marketSystemMapper.updateByKeyname("market_order_unpaid",configOrderBO.getMarket_order_unpaid());
        marketSystemMapper.updateByKeyname("market_order_comment",configOrderBO.getMarket_order_comment());

    }

    @Override
    public ConfigWxBO queryWx() {
        String market_wx_index_newValue = marketSystemMapper.selectByKeyname("market_wx_index_new");
        String market_wx_index_topicValue = marketSystemMapper.selectByKeyname("market_wx_index_topic");
        String market_wx_shareValue = marketSystemMapper.selectByKeyname("market_wx_share");
        String market_wx_index_brandValue = marketSystemMapper.selectByKeyname("market_wx_index_brand");
        String market_wx_catlog_goodsValue = marketSystemMapper.selectByKeyname("market_wx_catlog_goods");
        String market_wx_catlog_listValue = marketSystemMapper.selectByKeyname("market_wx_catlog_list");
        String market_wx_index_hotValue = marketSystemMapper.selectByKeyname("market_wx_index_hot");
        ConfigWxBO configWxBO = new ConfigWxBO(market_wx_index_newValue,
                                                market_wx_index_topicValue,
                                                market_wx_shareValue,
                                                market_wx_index_brandValue,
                                                market_wx_catlog_goodsValue,
                                                market_wx_catlog_listValue,
                                                market_wx_index_hotValue);
        return configWxBO;
    }

    @Override
    public void updateConfigWxBO(ConfigWxBO configWxBO) {
        marketSystemMapper.updateByKeyname("market_wx_index_new",configWxBO.getMarket_wx_index_new());
        marketSystemMapper.updateByKeyname("market_wx_index_topic",configWxBO.getMarket_wx_index_topic());
        marketSystemMapper.updateByKeyname("market_wx_share",configWxBO.getMarket_wx_share());
        marketSystemMapper.updateByKeyname("market_wx_index_brand",configWxBO.getMarket_wx_index_brand());
        marketSystemMapper.updateByKeyname("market_wx_catlog_goods",configWxBO.getMarket_wx_catlog_goods());
        marketSystemMapper.updateByKeyname("market_wx_catlog_list",configWxBO.getMarket_wx_catlog_list());
        marketSystemMapper.updateByKeyname("market_wx_index_hot",configWxBO.getMarket_wx_index_hot());
    }
}
